<template>
  <div class="contract-container">
    <!-- 背景装饰元素 -->
    <div class="background-decoration">
      <!-- 精美的动态背景 -->
      <div class="dynamic-background">
        <div class="building building-1"></div>
        <div class="building building-2"></div>
        <div class="building building-3"></div>
        <div class="building building-4"></div>
        <div class="building building-5"></div>
        <div class="cloud cloud-1"></div>
        <div class="cloud cloud-2"></div>
        <div class="cloud cloud-3"></div>
        <div class="sun"></div>
        <div class="light-ray ray-1"></div>
        <div class="light-ray ray-2"></div>
        <div class="light-ray ray-3"></div>
      </div>

      <!-- 浮动装饰元素 -->
      <div class="floating-shape shape-1"></div>
      <div class="floating-shape shape-2"></div>
      <div class="floating-shape shape-3"></div>
      <div class="floating-shape shape-4"></div>
      <div class="floating-shape shape-5"></div>
      <div class="floating-shape shape-6"></div>
    </div>

    <div class="contract-wrapper">
      <!-- 顶部导航栏 -->
      <div class="top-navbar">
        <div class="navbar-left">
          <h1 class="app-title">签约管理</h1>
        </div>
        <div class="navbar-center">
          <el-menu
              :default-active="activeIndex"
              mode="horizontal"
              @select="handleSelect"
              background-color="rgba(255, 255, 255, 0.1)"
              text-color="#fff"
              active-text-color="#4A90E2"
          >
            <el-menu-item index="1" @click="goToHome">首页</el-menu-item>
            <el-menu-item index="2" @click="goToSearch">房源搜索</el-menu-item>
            <el-menu-item index="3" @click="goToPublish">发布房源</el-menu-item>
            <el-menu-item index="4" @click="goToMessages">消息中心</el-menu-item>
          </el-menu>
        </div>
        <div class="navbar-right">
          <el-dropdown @command="handleUserCommand">
            <span class="user-info">
              <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <span class="username">张三</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="profile">个人资料</el-dropdown-item>
                <el-dropdown-item command="settings">设置</el-dropdown-item>
                <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>

      <div class="main-content">
        <!-- 侧边栏 -->
        <div class="sidebar">
          <el-menu
              :default-active="activeMenu"
              class="el-menu-vertical"
              background-color="rgba(0, 0, 0, 0.2)"
              text-color="#fff"
              active-text-color="#4A90E2"
          >
            <el-menu-item index="dashboard" @click="goToHome">
              <el-icon><House /></el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="search" @click="goToSearch">
              <el-icon><Search /></el-icon>
              <span>房源搜索</span>
            </el-menu-item>
            <el-sub-menu index="publish">
              <template #title>
                <el-icon><OfficeBuilding /></el-icon>
                <span>发布房源</span>
              </template>
              <el-menu-item index="publish-house" @click="goToPublishNew">发布新房源</el-menu-item>
              <el-menu-item index="my-houses" @click="goToMyHouses">我的房源</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="agent">
              <template #title>
                <el-icon><User /></el-icon>
                <span>中介申请</span>
              </template>
              <el-menu-item index="agent-apply" @click="goToAgentApply">申请中介</el-menu-item>
              <el-menu-item index="agent-status" @click="goToAgentStatus">申请状态</el-menu-item>
              <el-menu-item index="agent-houses" @click="goToAgentHouses">可代理房源</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="rental">
              <template #title>
                <el-icon><Key /></el-icon>
                <span>租房管理</span>
              </template>
              <el-menu-item index="tenant" @click="goToTenant">我是租客</el-menu-item>
              <el-menu-item index="landlord" @click="goToLandlord">我是房东</el-menu-item>
              <el-menu-item index="agent-rental" @click="goToAgentRental">中介租房</el-menu-item>
            </el-sub-menu>
            <el-menu-item index="contract" @click="goToContract">
              <el-icon><Document /></el-icon>
              <span>签约管理</span>
            </el-menu-item>
            <el-menu-item index="profile" @click="goToProfile">
              <el-icon><Setting /></el-icon>
              <span>个人资料</span>
            </el-menu-item>
          </el-menu>
        </div>

        <!-- 签约内容区 -->
        <div class="content-area">
          <div class="contract-header">
            <h2>签约管理</h2>
            <p>管理您的租赁合同申请和签署</p>
          </div>

          <div class="contract-content">
            <!-- 租客发起的签约申请 -->
            <el-card class="contract-card" v-if="userType === 'tenant'">
              <template #header>
                <div class="card-header">
                  <span>我发起的签约申请</span>
                </div>
              </template>

              <div class="contract-list">
                <el-table :data="tenantContracts" style="width: 100%">
                  <el-table-column prop="houseTitle" label="房源信息" width="200"></el-table-column>
                  <el-table-column prop="landlordName" label="房东" width="120"></el-table-column>
                  <el-table-column prop="status" label="状态" width="120">
                    <template #default="scope">
                      <el-tag :type="getContractStatusType(scope.row.status)">
                        {{ getContractStatusText(scope.row.status) }}
                      </el-tag>
                    </template>
                  </el-table-column>
                  <el-table-column prop="applyTime" label="申请时间" width="150"></el-table-column>
                  <el-table-column label="操作" width="200">
                    <template #default="scope">
                      <el-button
                          size="small"
                          @click="viewContractDetail(scope.row)"
                          :disabled="scope.row.status === 'rejected'"
                      >
                        {{ scope.row.status === 'rejected' ? '查看详情' : '查看进度' }}
                      </el-button>
                      <el-button
                          v-if="scope.row.status === 'drafting'"
                          size="small"
                          type="primary"
                          @click="signContract(scope.row)"
                      >
                        签署合同
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-card>

            <!-- 房东收到的签约申请 -->
            <el-card class="contract-card" v-if="userType === 'landlord'">
              <template #header>
                <div class="card-header">
                  <span>收到的签约申请</span>
                  <el-button type="primary" @click="refreshApplications">刷新</el-button>
                </div>
              </template>

              <div class="contract-list">
                <el-table :data="landlordApplications" style="width: 100%">
                  <el-table-column prop="houseTitle" label="房源信息" width="200"></el-table-column>
                  <el-table-column prop="tenantName" label="申请人" width="120"></el-table-column>
                  <el-table-column prop="applyTime" label="申请时间" width="150"></el-table-column>
                  <el-table-column prop="leaseTerm" label="租期" width="100">
                    <template #default="scope">
                      {{ scope.row.leaseTerm }}个月
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" width="250">
                    <template #default="scope">
                      <el-button size="small" @click="viewApplicationDetail(scope.row)">查看详情</el-button>
                      <el-button size="small" type="success" @click="approveApplication(scope.row)">同意</el-button>
                      <el-button size="small" type="danger" @click="rejectApplication(scope.row)">拒绝</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-card>

            <!-- 房东拟定合同 -->
            <el-card class="contract-card" v-if="userType === 'landlord' && showContractDraft">
              <template #header>
                <div class="card-header">
                  <span>拟定合同</span>
                  <div>
                    <el-button @click="cancelDraft">取消</el-button>
                    <el-button type="primary" @click="submitContractDraft">提交</el-button>
                  </div>
                </div>
              </template>

              <div class="contract-draft">
                <el-form :model="contractDraft" label-width="120px">
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="押金条款">
                        <el-input
                            v-model="contractDraft.depositTerms"
                            type="textarea"
                            :rows="3"
                            placeholder="请输入押金条款（通常为1-3个月租金，注明退还条件）"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="房东义务">
                        <el-input
                            v-model="contractDraft.landlordObligations"
                            type="textarea"
                            :rows="4"
                            placeholder="请输入房东义务"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="租客义务">
                        <el-input
                            v-model="contractDraft.tenantObligations"
                            type="textarea"
                            :rows="4"
                            placeholder="请输入租客义务"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="违约责任">
                        <el-input
                            v-model="contractDraft.defaultProvisions"
                            type="textarea"
                            :rows="5"
                            placeholder="请输入违约责任条款"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="特殊条款">
                        <el-input
                            v-model="contractDraft.specialClauses"
                            type="textarea"
                            :rows="4"
                            placeholder="请输入特殊条款"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="争议解决">
                        <el-input
                            v-model="contractDraft.disputeResolution"
                            type="textarea"
                            :rows="3"
                            placeholder="请输入争议解决方式"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="保存为模板">
                        <el-switch
                            v-model="contractDraft.saveAsTemplate"
                            active-text="是"
                            inactive-text="否"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </el-card>

            <!-- 合同详情 -->
            <el-card class="contract-card" v-if="showContractDetail">
              <template #header>
                <div class="card-header">
                  <span>合同详情</span>
                  <div>
                    <el-button @click="backToList">返回列表</el-button>
                    <el-button
                        v-if="currentContract.status === 'drafting' && userType === 'tenant'"
                        type="primary"
                        @click="signContract(currentContract)"
                    >
                      签署合同
                    </el-button>
                  </div>
                </div>
              </template>

              <div class="contract-detail">
                <div class="contract-info">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">房源信息：</span>
                        <span class="value">{{ currentContract.houseTitle }}</span>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">房东：</span>
                        <span class="value">{{ currentContract.landlordName }}</span>
                      </div>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">申请人：</span>
                        <span class="value">{{ currentContract.tenantName }}</span>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">申请时间：</span>
                        <span class="value">{{ currentContract.applyTime }}</span>
                      </div>
                    </el-col>
                  </el-row>

                  <el-row :gutter="20">
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">租期：</span>
                        <span class="value">{{ currentContract.leaseTerm }}个月</span>
                      </div>
                    </el-col>
                    <el-col :span="12">
                      <div class="info-item">
                        <span class="label">状态：</span>
                        <span class="value">
                          <el-tag :type="getContractStatusType(currentContract.status)">
                            {{ getContractStatusText(currentContract.status) }}
                          </el-tag>
                        </span>
                      </div>
                    </el-col>
                  </el-row>

                  <div v-if="currentContract.rejectReason" class="info-item">
                    <span class="label">拒绝理由：</span>
                    <span class="value reject-reason">{{ currentContract.rejectReason }}</span>
                  </div>
                </div>

                <div class="contract-terms" v-if="currentContract.status !== 'pending' && currentContract.status !== 'rejected'">
                  <h3>合同条款</h3>

                  <div class="term-section">
                    <h4>押金条款</h4>
                    <p>{{ currentContract.depositTerms }}</p>
                  </div>

                  <div class="term-section">
                    <h4>房东义务</h4>
                    <p>{{ currentContract.landlordObligations }}</p>
                  </div>

                  <div class="term-section">
                    <h4>租客义务</h4>
                    <p>{{ currentContract.tenantObligations }}</p>
                  </div>

                  <div class="term-section">
                    <h4>违约责任</h4>
                    <p>{{ currentContract.defaultProvisions }}</p>
                  </div>

                  <div class="term-section">
                    <h4>特殊条款</h4>
                    <p>{{ currentContract.specialClauses }}</p>
                  </div>

                  <div class="term-section">
                    <h4>争议解决</h4>
                    <p>{{ currentContract.disputeResolution }}</p>
                  </div>
                </div>
              </div>
            </el-card>

            <!-- 拒绝申请对话框 -->
            <el-dialog
                v-model="showRejectDialog"
                title="拒绝申请"
                width="500px"
            >
              <el-form>
                <el-form-item label="拒绝理由">
                  <el-input
                      v-model="rejectReason"
                      type="textarea"
                      :rows="4"
                      placeholder="请输入拒绝理由"
                  />
                </el-form-item>
              </el-form>
              <template #footer>
                <span class="dialog-footer">
                  <el-button @click="showRejectDialog = false">取消</el-button>
                  <el-button type="primary" @click="confirmReject">确定</el-button>
                </span>
              </template>
            </el-dialog>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  House,
  Search,
  OfficeBuilding,
  User,
  Key,
  ChatLineSquare,
  Setting,
  Document
} from '@element-plus/icons-vue'

const router = useRouter()
const activeMenu = ref('contract')
const activeIndex = ref('1')
const userType = ref('tenant') // tenant or landlord
const showContractDraft = ref(false)
const showContractDetail = ref(false)
const showRejectDialog = ref(false)
const rejectReason = ref('')
const currentApplication = ref(null)
const currentContract = ref({})

// 租客发起的签约申请
const tenantContracts = ref([
  {
    id: 1,
    houseTitle: '精致一居室公寓',
    landlordName: '李四',
    status: 'pending', // pending, approved, rejected, drafting, signed
    applyTime: '2023-06-15 14:30',
    leaseTerm: 12,
    rejectReason: ''
  },
  {
    id: 2,
    houseTitle: '豪华两居室',
    landlordName: '王五',
    status: 'approved',
    applyTime: '2023-06-10 10:15',
    leaseTerm: 24,
    rejectReason: ''
  },
  {
    id: 3,
    houseTitle: '舒适三居室',
    landlordName: '赵六',
    status: 'drafting',
    applyTime: '2023-06-05 09:45',
    leaseTerm: 12,
    rejectReason: '',
    depositTerms: '押金为两个月租金，退租时房屋设施无损坏且结清水电费后退还',
    landlordObligations: '交房时保证房屋无产权纠纷，设施正常使用，配合办理暂住证等手续',
    tenantObligations: '禁止转租/分租，不得擅自拆改房屋结构，禁止堆放易燃易爆物品',
    defaultProvisions: '租客逾期支付租金：按日加收2%滞纳金，超15日可解除合同；提前退租：扣减押金或支付2个月租金作为违约金。房东无故收回房屋：赔偿租客2个月租金+搬家费；未履行维修义务：租客可自行维修并抵扣租金',
    specialClauses: '房屋维修：自然损坏由房东负责，人为损坏由租客承担。合同终止：租客退租需提前30日书面通知，并结清费用；房东售房需提前60日通知，租客享有优先购买权',
    disputeResolution: '协商不成时，向房屋所在地法院提起诉讼'
  }
])

// 房东收到的签约申请
const landlordApplications = ref([
  {
    id: 101,
    houseTitle: '精致一居室公寓',
    tenantName: '张三',
    applyTime: '2023-06-15 14:30',
    leaseTerm: 12,
    realName: '张三',
    identityCard: '110101199001011234',
    phone: '13812345678'
  },
  {
    id: 102,
    houseTitle: '豪华两居室',
    tenantName: '李四',
    applyTime: '2023-06-12 11:20',
    leaseTerm: 24,
    realName: '李四',
    identityCard: '110101199002021234',
    phone: '13987654321'
  }
])

// 合同草案
const contractDraft = reactive({
  depositTerms: '押金为两个月租金，退租时房屋设施无损坏且结清水电费后退还',
  landlordObligations: '交房时保证房屋无产权纠纷，设施正常使用，配合办理暂住证等手续（如需）',
  tenantObligations: '禁止转租/分租（或约定转租房东书面同意），不得擅自拆改房屋结构，卫生及安全管理（如"禁止堆放易燃易爆物品"）',
  defaultProvisions: '①租客违约：逾期支付租金：按日加收2%滞纳金，超15日可解除合同；提前退租：扣减押金或支付2个月租金作为违约金。②房东违约：无故收回房屋：赔偿租客2个月租金+搬家费；未履行维修义务：租客可自行维修并抵扣租金',
  specialClauses: '①房屋维修：自然损坏：房东负责（如水管老化破裂）；人为损坏：租客承担（如打碎玻璃窗）。②合同终止：租客退租需提前30日书面通知，并结清费用；房东售房需提前60日通知，租客享有优先购买权',
  disputeResolution: '协商不成时，向房屋所在地法院提起诉讼',
  saveAsTemplate: true
})

// 获取合同状态类型
const getContractStatusType = (status) => {
  const statusTypes = {
    'pending': 'warning',
    'approved': 'success',
    'rejected': 'danger',
    'drafting': 'primary',
    'signed': 'success'
  }
  return statusTypes[status] || 'info'
}

// 获取合同状态文本
const getContractStatusText = (status) => {
  const statusTexts = {
    'pending': '待处理',
    'approved': '已同意',
    'rejected': '已拒绝',
    'drafting': '拟定中',
    'signed': '已签署'
  }
  return statusTexts[status] || '未知状态'
}

// 顶部导航栏跳转
const goToHome = () => {
  router.push('/')
}

const goToSearch = () => {
  router.push('/house/search')
}

const goToPublish = () => {
  router.push('/house/publish')
}

const goToMessages = () => {
  router.push('/message')
}

// 用户命令处理
const handleUserCommand = async (command) => {
  switch (command) {
    case 'profile':
      router.push('/profile')
      break
    case 'settings':
      router.push('/settings')
      break
    case 'logout':
      try {
        const { userLogout } = await import('@/utils/auth')
        await userLogout()
        ElMessage.success('退出登录成功')
        router.push('/login')
      } catch (error) {
        console.error('登出失败:', error)
        // 即使登出API失败，也要清除本地状态并跳转
        ElMessage.success('退出登录成功')
        router.push('/login')
      }
      break
  }
}

// 侧边栏跳转
const goToPublishNew = () => {
  router.push('/house/publish')
}

const goToMyHouses = () => {
  router.push('/house/my-houses')
}

const goToAgentApply = () => {
  router.push('/agent/apply')
}

const goToAgentStatus = () => {
  router.push('/agent/status')
}

const goToAgentHouses = () => {
  router.push('/agent/houses')
}

const goToTenant = () => {
  router.push('/rental/tenant')
}

const goToLandlord = () => {
  router.push('/rental/landlord')
}

const goToAgentRental = () => {
  router.push('/rental/agent')
}

const goToContract = () => {
  router.push('/contract')
}

const goToProfile = () => {
  router.push('/profile')
}

// 菜单选择处理
const handleSelect = (key) => {
  switch (key) {
    case '1':
      router.push('/')
      break
    case '2':
      router.push('/house/search')
      break
    case '3':
      router.push('/house/publish')
      break
    case '4':
      router.push('/message')
      break
  }
}

// 刷新申请列表
const refreshApplications = () => {
  ElMessage.success('刷新成功')
}

// 查看申请详情
const viewApplicationDetail = (application) => {
  currentApplication.value = application
  showContractDetail.value = true
  currentContract.value = {
    ...application,
    status: 'pending'
  }
}

// 同意申请
const approveApplication = (application) => {
  ElMessageBox.confirm(
      '确定要同意该签约申请吗？',
      '同意申请',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    // 模拟同意申请
    setTimeout(() => {
      ElMessage.success('已同意该签约申请')

      // 更新房东申请列表
      const index = landlordApplications.value.findIndex(item => item.id === application.id)
      if (index > -1) {
        landlordApplications.value.splice(index, 1)
      }

      // 显示合同拟定界面
      showContractDraft.value = true
      currentApplication.value = application
    }, 1000)
  }).catch(() => {
    // 用户取消操作
  })
}

// 拒绝申请
const rejectApplication = (application) => {
  currentApplication.value = application
  rejectReason.value = ''
  showRejectDialog.value = true
}

// 确认拒绝
const confirmReject = () => {
  if (!rejectReason.value.trim()) {
    ElMessage.error('请输入拒绝理由')
    return
  }

  // 模拟拒绝申请
  setTimeout(() => {
    ElMessage.success('已拒绝该签约申请')
    showRejectDialog.value = false

    // 更新房东申请列表
    const index = landlordApplications.value.findIndex(item => item.id === currentApplication.value.id)
    if (index > -1) {
      landlordApplications.value.splice(index, 1)
    }

    // 更新租客合同列表
    const tenantIndex = tenantContracts.value.findIndex(item => item.houseTitle === currentApplication.value.houseTitle)
    if (tenantIndex > -1) {
      tenantContracts.value[tenantIndex].status = 'rejected'
      tenantContracts.value[tenantIndex].rejectReason = rejectReason.value
    }
  }, 1000)
}

// 取消拟定合同
const cancelDraft = () => {
  showContractDraft.value = false
  currentApplication.value = null
}

// 提交合同草案
const submitContractDraft = () => {
  ElMessageBox.confirm(
      '确定要提交拟定的合同吗？',
      '提交合同',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    // 模拟提交合同草案
    setTimeout(() => {
      ElMessage.success('合同已提交，请等待租客签署')
      showContractDraft.value = false

      // 更新租客合同列表
      const tenantIndex = tenantContracts.value.findIndex(item => item.houseTitle === currentApplication.value.houseTitle)
      if (tenantIndex > -1) {
        tenantContracts.value[tenantIndex].status = 'drafting'
        tenantContracts.value[tenantIndex].depositTerms = contractDraft.depositTerms
        tenantContracts.value[tenantIndex].landlordObligations = contractDraft.landlordObligations
        tenantContracts.value[tenantIndex].tenantObligations = contractDraft.tenantObligations
        tenantContracts.value[tenantIndex].defaultProvisions = contractDraft.defaultProvisions
        tenantContracts.value[tenantIndex].specialClauses = contractDraft.specialClauses
        tenantContracts.value[tenantIndex].disputeResolution = contractDraft.disputeResolution
      }

      currentApplication.value = null
    }, 1000)
  }).catch(() => {
    // 用户取消操作
  })
}

// 查看合同详情
const viewContractDetail = (contract) => {
  showContractDetail.value = true
  currentContract.value = contract
}

// 签署合同
const signContract = (contract) => {
  ElMessageBox.confirm(
      '确定要签署该合同吗？签署后将生成PDF文件并存档。',
      '签署合同',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    // 模拟签署合同
    setTimeout(() => {
      ElMessage.success('合同签署成功')
      showContractDetail.value = false

      // 更新合同状态
      const index = tenantContracts.value.findIndex(item => item.id === contract.id)
      if (index > -1) {
        tenantContracts.value[index].status = 'signed'
      }
    }, 1000)
  }).catch(() => {
    // 用户取消操作
  })
}

// 返回列表
const backToList = () => {
  showContractDetail.value = false
  currentContract.value = {}
}
</script>

<style scoped>
.contract-container {
  display: flex;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
}

.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
}

/* 精美的动态背景 */
.dynamic-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, #1a2980, #26d0ce);
  overflow: hidden;
}

/* 建筑物 */
.building {
  position: absolute;
  bottom: 0;
  background: rgba(30, 30, 50, 0.8);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
}

.building-1 {
  left: 10%;
  width: 80px;
  height: 300px;
  animation: buildingGlow 4s infinite alternate;
}

.building-2 {
  left: 25%;
  width: 120px;
  height: 400px;
  animation: buildingGlow 5s infinite alternate-reverse;
}

.building-3 {
  left: 45%;
  width: 100px;
  height: 350px;
  animation: buildingGlow 6s infinite alternate;
}

.building-4 {
  left: 65%;
  width: 140px;
  height: 450px;
  animation: buildingGlow 4.5s infinite alternate-reverse;
}

.building-5 {
  left: 80%;
  width: 90px;
  height: 320px;
  animation: buildingGlow 5.5s infinite alternate;
}

@keyframes buildingGlow {
  0% {
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
  }
  100% {
    box-shadow: 0 -5px 25px rgba(100, 200, 255, 0.6);
  }
}

/* 云朵 */
.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  filter: blur(2px);
}

.cloud-1 {
  top: 20%;
  left: 5%;
  width: 80px;
  height: 30px;
  animation: cloudMove 25s linear infinite;
}

.cloud-2 {
  top: 35%;
  left: 70%;
  width: 120px;
  height: 40px;
  animation: cloudMove 30s linear infinite;
}

.cloud-3 {
  top: 15%;
  left: 40%;
  width: 100px;
  height: 35px;
  animation: cloudMove 35s linear infinite;
}

@keyframes cloudMove {
  0% {
    transform: translateX(-100px);
  }
  100% {
    transform: translateX(calc(100vw + 100px));
  }
}

/* 太阳 */
.sun {
  position: absolute;
  top: 80px;
  right: 100px;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, #ffeb3b, #ffc107);
  border-radius: 50%;
  box-shadow: 0 0 40px #ff9800, 0 0 80px #ff5722;
  animation: sunPulse 3s infinite alternate;
}

@keyframes sunPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 40px #ff9800, 0 0 80px #ff5722;
  }
  100% {
    transform: scale(1.1);
    box-shadow: 0 0 60px #ff9800, 0 0 100px #ff5722;
  }
}

/* 光线 */
.light-ray {
  position: absolute;
  top: 120px;
  right: 140px;
  width: 400px;
  height: 200px;
  background: linear-gradient(to right, transparent, rgba(255, 235, 59, 0.2), transparent);
  transform-origin: left center;
  animation: rayRotate 10s infinite linear;
}

.ray-1 {
  transform: rotate(0deg);
  animation-delay: 0s;
}

.ray-2 {
  transform: rotate(60deg);
  animation-delay: 2s;
}

.ray-3 {
  transform: rotate(120deg);
  animation-delay: 4s;
}

@keyframes rayRotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 浮动装饰元素 */
.floating-shape {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 15s infinite linear;
}

.shape-1 {
  width: 300px;
  height: 300px;
  top: -100px;
  left: -100px;
  animation-duration: 20s;
  background: radial-gradient(circle, rgba(74, 144, 226, 0.2) 0%, transparent 70%);
}

.shape-2 {
  width: 200px;
  height: 200px;
  bottom: -80px;
  right: -80px;
  animation-duration: 25s;
  animation-direction: reverse;
  background: radial-gradient(circle, rgba(255, 107, 107, 0.2) 0%, transparent 70%);
}

.shape-3 {
  width: 150px;
  height: 150px;
  top: 30%;
  right: 20%;
  animation-duration: 15s;
  background: radial-gradient(circle, rgba(80, 227, 194, 0.2) 0%, transparent 70%);
}

.shape-4 {
  width: 100px;
  height: 100px;
  bottom: 20%;
  left: 20%;
  animation-duration: 18s;
  animation-direction: reverse;
  background: radial-gradient(circle, rgba(255, 209, 102, 0.2) 0%, transparent 70%);
}

.shape-5 {
  width: 250px;
  height: 250px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-duration: 22s;
  background: radial-gradient(circle, rgba(155, 89, 182, 0.2) 0%, transparent 70%);
}

.shape-6 {
  width: 180px;
  height: 180px;
  top: 70%;
  left: 10%;
  animation-duration: 28s;
  background: radial-gradient(circle, rgba(231, 76, 60, 0.2) 0%, transparent 70%);
}

@keyframes float {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(20px, 20px) rotate(90deg);
  }
  50% {
    transform: translate(0, 40px) rotate(180deg);
  }
  75% {
    transform: translate(-20px, 20px) rotate(270deg);
  }
  100% {
    transform: translate(0, 0) rotate(360deg);
  }
}

.contract-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  z-index: 1;
  position: relative;
}

.top-navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 30px;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-title {
  color: white;
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.navbar-center {
  flex: 1;
  margin: 0 20px;
}

:deep(.el-menu--horizontal) {
  border: none;
  background: transparent !important;
}

:deep(.el-menu--horizontal .el-menu-item) {
  color: white;
  border: none;
}

:deep(.el-menu--horizontal .el-menu-item:hover) {
  background: rgba(255, 255, 255, 0.2) !important;
}

:deep(.el-menu--horizontal .el-menu-item.is-active) {
  color: #4A90E2 !important;
  border: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: white;
}

.username {
  font-size: 16px;
  font-weight: 500;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 250px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  padding: 20px 0;
  height: 100%;
  box-shadow: 3px 0 10px rgba(0, 0, 0, 0.2);
}

.el-menu-vertical {
  border: none !important;
  height: 100%;
}

.el-menu-item,
.el-sub-menu__title {
  margin: 5px 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
}

.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  padding: 20px;
}

.contract-header {
  margin-bottom: 30px;
}

.contract-header h2 {
  color: #2c3e50;
  font-size: 28px;
  margin: 0 0 10px;
}

.contract-header p {
  color: #7f8c8d;
  margin: 0;
}

.contract-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.contract-card {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.contract-list :deep(.el-table) {
  margin-top: 20px;
}

.reject-reason {
  color: #f56c6c;
}

.contract-detail {
  padding: 20px 0;
}

.contract-info {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 30px;
}

.info-item {
  display: flex;
  margin-bottom: 15px;
}

.info-item .label {
  width: 100px;
  font-weight: 600;
  color: #2c3e50;
}

.info-item .value {
  flex: 1;
  color: #7f8c8d;
}

.contract-terms h3 {
  margin: 0 0 20px;
  font-size: 22px;
  color: #2c3e50;
}

.term-section {
  margin-bottom: 25px;
}

.term-section h4 {
  margin: 0 0 10px;
  font-size: 18px;
  color: #2c3e50;
}

.term-section p {
  margin: 0;
  line-height: 1.6;
  color: #7f8c8d;
  white-space: pre-line;
}

.contract-draft :deep(.el-form-item) {
  margin-bottom: 25px;
}

@media (max-width: 992px) {
  .sidebar {
    width: 80px;
  }

  .app-title,
  .el-menu-item span,
  .el-sub-menu__title span {
    display: none;
  }

  .contract-header {
    text-align: center;
  }

  .card-header {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }

  .info-item {
    flex-direction: column;
    gap: 5px;
  }

  .info-item .label {
    width: auto;
  }
}
</style>
